package com.xyx.bloodoxygenlib.impls;

import android.util.Log;

import com.xyx.bloodoxygenlib.interfaces.ISender;

import java.io.IOException;
import java.io.OutputStream;

public class OutputStreamSender implements ISender {
    /**
     * 输出流
     */
    private OutputStream os;

    /**
     * 构造函数
     * @param os
     */
    public OutputStreamSender(OutputStream os) {
        this.os = os;
    }

    @Override // com.creative.base.Isender
    public void send(byte[] d) throws IOException {
        if (this.os != null) {
            this.os.write(d);
            this.os.flush();
        }
    }

    @Override // com.creative.base.Isender
    public void close() {
        if (this.os != null) {
            try {
                this.os.flush();
                this.os.close();
                this.os = null;
            } catch (IOException e) {
                e.printStackTrace();
                Log.e("OutputStreamSender", "OutputStreamSender close error:" + e.getMessage());
            }
        }
    }
}
